import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;


public class Derby implements Iterable<Bucket>{
	private String name;
	private List<Bucket> allBuckets;
	
	public Derby(String inName) {
		name = inName;
		allBuckets = new ArrayList<>();
	}
	
	public void register(Bucket aBucket) {
		allBuckets.add(aBucket);
	}
	
	public void addFish(Bucket looksLike, Fish aFish) {
		int position = allBuckets.indexOf(looksLike);
		Bucket realBucket = allBuckets.get(position);
		
		realBucket.addFish(aFish);
	}
	
	
	public Iterator<Bucket> iterByFirstLast() {
		Collections.sort(allBuckets, Bucket.byLastNameFirstName());
		
		return allBuckets.iterator();
	}
	
	public Bucket getWinner() {
		return Collections.max(allBuckets);
	}

	@Override
	public Iterator<Bucket> iterator() {
		Collections.sort(allBuckets);
		Collections.reverse(allBuckets);

		Iterator<Bucket> iter = allBuckets.iterator();
		return iter;
	}
}
